<template>
  <!-- 系统设置模块-解除锁定-->
  <div class="fillcontain">
    <!-- 标题 -->
    <div class="fastQuery">
      <el-row>
        <el-col :span="6" class="common-box">
          <el-col :span="10" class="common-lab">
            <label class="labelName">受理号</label>
          </el-col>
          <el-col :span="14">
            <el-input clearable v-model="applnum" placeholder=""></el-input>
          </el-col>
        </el-col>
        <el-col :span="6" class="common-box">
          <el-col :span="10" class="common-lab">
            <label class="labelName">机构</label>
          </el-col>
          <el-col :span="14">
            <el-input clearable v-model="companybranch" placeholder=""></el-input>
          </el-col>
        </el-col>
        <el-col :span="6" class="common-box">
          <el-col :span="10" class="common-lab">
            <label class="labelName">受理日期</label>
          </el-col>
          <el-col :span="14">
            <el-date-picker
                v-model="hprrcvdt"
                format="yyyyMMdd"
                value-format="yyyyMMdd"
                type="date">
                </el-date-picker>
           <!--<el-input clearable v-model="hprrcvdt" placeholder=""></el-input>-->
          </el-col>
        </el-col>
        <el-col :span="6" class="text_center">
          <el-button type="primary" icon="el-icon-search" @click="getPolicyRList(1)"></el-button>
          <el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
        </el-col>
      </el-row>
    </div>
        <div class="contain">
        <!-- 操作按钮 -->
        <div class="table_container">
          <el-table
              :data="policyRList"
              highlight-current-row
              header-cell-class-name="table-header-class"
              style="width:100%">
            <el-table-column property="applnum" label="受理号"></el-table-column>
            <el-table-column property="chdrnum" label="保单号"></el-table-column>
            <el-table-column label="机构">
              <template slot-scope="scope">
                {{scope.row.agntcoy + scope.row.cntbranch}}
              </template>
            </el-table-column>
            <el-table-column label="锁状态">
				<template slot-scope="scope">
				  <el-col :span="12">
				        <span v-if="scope.row.acntchn01=='Y'">
				          Y
				        </span>
				        <span v-else>
						  N
				        </span>
				  </el-col>
				</template>
			</el-table-column>
            <el-table-column
                fixed="right"
                label="操作"
                align='center'>
              <template slot-scope="scope">
                <el-col :span="12">
                    <el-button type="primary" plain @click="unlock(scope.row)">
                      <span v-if="scope.row.acntchn01=='Y'">
                        解锁
                      </span>
                      <span v-else>
                        锁定
                      </span>
                    </el-button>
                </el-col>
              </template>
            </el-table-column>
          </el-table>
          <el-row>
            <el-col :span="24">
              <div class="pagination">
                <el-pagination
                    background
                    v-if='paginations.total > 0'
                    :page-sizes="paginations.pageSizes"
                    :page-size="paginations.pageSize"
                    :layout="paginations.layout"
                    :total="paginations.total"
                    :current-page='paginations.pageIndex'
                    @current-change='handleCurrentChange'
                    @size-change='handleSizeChange'>
                </el-pagination>
              </div>
            </el-col>
          </el-row>
        </div>
    </div>
  </div>
</template>
<script>
  import {
    getPolicyRList,
    policyRUnlock
  } from "@/api/setting";
  import constant from "@/utils/constant";
  import {Message, MessageBox} from 'element-ui';
  export default {
    data() {
      return {
        policyRList: [],
        hprrcvdt:'',
        applnum:'',
        companybranch:'',
        //需要给分页组件传的信息
        paginations: {
          total: 0,        // 总数
          pageIndex: 1,  // 当前位于哪页
          pageSize: 10,   // 1页显示多少条
          pageSizes: [5, 10, 15, 20],  //每页显示多少条
          layout: "total, sizes, prev, pager, next, jumper",   // 翻页属性
        },
      }
    },
    created() {
      
    },
    mounted() {
    },
    methods: {
      resetSearch(){
         this.applnum = '';
         this.hprrcvdt = '';
         this.companybranch = '';
      },
      getPolicyRList(falg){
        if(!this.applnum&&!this.hprrcvdt&&!this.companybranch){
           this.$message.error('请输入查询条件！');
           return false;
        }
        this.$store.dispatch('loading/CHNAGE_SUBLOADING',true);
        let para = {
            pageNumber: this.paginations.pageIndex,
            pageSize: this.paginations.pageSize,
            applnum: this.applnum,
            hprrcvdt: this.hprrcvdt,
            companybranch: this.companybranch
        };
        getPolicyRList(para).then(res =>{
            if(res.resultCode == constant.SUCCESS){
                this.paginations.total = res.data.total;
                this.policyRList = res.data.list; 
                if(this.policyRList.length == 0 && falg == 1){
                   this.$message({
                     message: '无符合条件记录！',
                     type: 'error'
                  });
                }
            }
            this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
        }).catch(err =>{
            console.log(err);
            this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
        })
      },
      // 每页多少条切换
      handleSizeChange(pageSize) {
        this.paginations.pageIndex = 1;
        this.paginations.pageSize = pageSize;
        this.getPolicyRList(0);
      },
      // 上下分页
      handleCurrentChange(page) {
        this.paginations.pageIndex = page;
        this.getPolicyRList(0);
      },
      unlock(row){
        let title = '';
        let acntchn01 = '';
        if(row.acntchn01=='Y'){
          title = '解锁确认？';
          acntchn01 = 'N';
        }else{
          title = '锁定确认？';
          acntchn01 = 'Y';
        }
        MessageBox.confirm(title, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
           this.$store.dispatch('loading/CHNAGE_SUBLOADING',true);
              let para = {
                  applnum: row.applnum,
                  acntchn01: acntchn01
              };
              policyRUnlock(para).then(res =>{
                  if(res.resultCode == constant.SUCCESS){
                    if(row.acntchn01=='Y'){
                        title = '解锁确认？';
                      }else{
                        title = '锁定确认？';
                      }
                      this.$message({
                        message: '已解锁！',
                        type: 'success'
                      });
                      this.getPolicyRList(0);
                  }
                  this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
              }).catch(err =>{
                  console.log(err);
                  this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
              })
        });
      }
    },
    computed: {},
  }
</script>
<style lang="less" scoped>
  .fillcontain {
    padding-bottom: 0;

    .fastQuery {
      padding: 15px 20px 10px 20px;
      background: #fff;

      .fastQuery_title {
        color: #666;
        padding: 6px 0px;
      }
    }
  }

  .contain {
    background: #fff;
    padding: 10px;
    margin-bottom: 20px;
  }

  .pagination {
    padding: 10px 20px;
    text-align: right;
  }
</style>
